<template>
  <div>
    <el-tabs v-model="activeName" @tab-click="handleSizeChange(10)">
      <el-tab-pane label="用户订单" name="first">
        <div class="base-table-wrap">
          <el-table :data="tableData.list" stripe style="width: 100%">
            <el-table-column prop="ordercode" label="订单号" min-width="140" align="center"></el-table-column>
            <el-table-column prop="businessname" label="商家" min-width="140" align="center"></el-table-column>
            <el-table-column prop="useraddress" label="订单收货地址" min-width="180" align="center">
              <template slot-scope="scope">
                <div>{{scope.row.useraddress}}{{scope.row.address}}</div>
              </template>
            </el-table-column>
            <el-table-column label="支付信息" min-width="120" align="center">
              <template slot-scope="scope">
                <div>{{scope.row.totalpay}}</div>
                <div> {{scope.row.ispay == '1' ?(scope.row.paytype=='0'?'支付宝':scope.row.paytype=='1'?
                  '微信':scope.row.paytype=='2'?'钱包': scope.row.paytype == '3' ? '微信公众号': scope.row.paytype=='4'?'小程序':'已支付') : '未支付' }}</div>
              </template>
            </el-table-column>
            <el-table-column prop="createtime" label="支付时间" min-width="120" align="center"></el-table-column>
          </el-table>
          <!-- 复制 el-table v-loading  v-loading无法快速响应 所有自定义 -->
          <div class="base-directives-loading" v-show="isloadingTable">
            <div class="el-loading-spinner">
              <svg viewBox="25 25 50 50" class="circular">
                <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
              </svg>
            </div>
          </div>
          <div class="base-pagination clearfix">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page.sync="newPage" :pageSize='pageSize'
                           :page-sizes="[10, 20, 30, 40]" background layout="total,sizes, prev, pager, next, jumper"
                           :total="tableData.total">
            </el-pagination>
          </div>
        </div>
      </el-tab-pane>

      <el-tab-pane label="收货地址" name="second">
        <div class="base-table-wrap" >
          <el-table :data="tableData.list" stripe style="width: 100%">
            <el-table-column type="index" label="#" width="40" align="center"></el-table-column>
            <el-table-column prop="name" label="用户名" min-width="120" align="center"></el-table-column>
            <el-table-column prop="mobile" label="收货手机号" min-width="120" align="center"></el-table-column>
            <el-table-column label="收货地址" min-width="500" align="left">
             <template slot-scope="scope">
                <div>{{scope.row.useraddress}}{{scope.row.address}}</div>
              </template>
            </el-table-column>
          </el-table>
          <div class="base-directives-loading" v-show="isloadingTable">
            <div class="el-loading-spinner">
              <svg viewBox="25 25 50 50" class="circular">
                <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
              </svg>
            </div>
          </div>
          <div class="base-pagination clearfix">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page.sync="newPage" :pageSize='pageSize'
                           :page-sizes="[10, 20, 30, 40]" background layout="total,sizes, prev, pager, next, jumper"
                           :total="tableData.total">
            </el-pagination>
          </div>

        </div>
      </el-tab-pane>
    </el-tabs>
  </div>

</template>
<script>
  export default {
    data() {
      return {
        params: { //查询数据
          page: 0,
          size: 10
        },
        isloadingTable: false,
        checkData: {},
        dialogTableVisible: false,
        tableData: {}, //表单数据
        newPage: 1, //显示当前page
        pageSize:10,
        activeName: 'first'

      };
    },
    methods: {
      handleSizeChange(size) { //设置分页数量
        this.params.size = size
        this.pageSize = size
        this.newPage = 1
        this.params.page = 0
        this.getTableList(this.activeName)
      },
      handleCurrentChange(page) { //切换分页
        this.params.page = page - 1
        this.getTableList(this.activeName)
      },
      getTableList(type) {
        const params = { ...this.params }
        params.userid = this.$route.query.id
        this.isloadingTable = true
        if (type =='first') {
          this.$http.get('/server/cuser/cuserOrderList?' + this.qs.stringify(params)).then(res => {
            if (res.data.success) {
              this.tableData = res.data.data
            }
          }).finally(() => { this.isloadingTable = false })
        } else if (type == 'second') {
          this.$http.get('/server/cuser/cuserAddressList?' + this.qs.stringify(params)).then(res => {
            if (res.data.success) {
              this.tableData = res.data.data
            }
          }).finally(() => { this.isloadingTable = false })
        } else {
          console.log('永远不会执行！！！')
        }
      },
    },

    mounted() {
      this.getTableList(this.activeName)
    },
  };
</script>
